package com.bjpowernode.services.impls;

import com.alibaba.excel.EasyExcel;
import com.bjpowernode.constants.Constant;
import com.bjpowernode.entities.TClue;
import com.bjpowernode.listeners.ClueExcelListener;
import com.bjpowernode.mappers.TClueMapper;
import com.bjpowernode.querys.BaseQuery;
import com.bjpowernode.excels.ClueExcel;
import com.bjpowernode.services.ClueService;
import com.bjpowernode.utils.LoginInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.io.InputStream;
import java.util.List;

@Service
public class ClueServiceImpl implements ClueService {
    @Resource
    private TClueMapper tClueMapper;

    @Override
    public TClue getClueById(Integer id) {
        return tClueMapper.selectById(id);
    }

    @Override
    public PageInfo<TClue> getCluesByPage(Integer current) {
        PageHelper.startPage(current, Constant.PAGE_SIZE);
        List<TClue> tUserList = tClueMapper.selectByPage(new BaseQuery());
        return new PageInfo<>(tUserList);
    }

    @Override
    public void importExcel(InputStream inputStream) {
        Integer loginUserId = LoginInfoUtil.getCurrentLoginUser().getId();
        EasyExcel.read(inputStream, ClueExcel.class, new ClueExcelListener(tClueMapper, loginUserId)).sheet().doRead();
    }
}
